﻿using System.Collections.Generic;
using System.Linq;
using System.Windows;

namespace Poet
{
    static class Helper
    {
        public static List<T> LogicalDescendants<T>(this UIElement element) where T : UIElement
        {
            var ret = new List<T>();
            var children = LogicalTreeHelper.GetChildren(element).OfType<UIElement>().ToList();
            ret.AddRange(children.OfType<T>());

            foreach (var frameworkElement in children)
            {
                ret.AddRange(frameworkElement.LogicalDescendants<T>());
            }

            return ret;
        }
    }
}
